package xyhoo.springframework.core;

public abstract class NestedExceptionUtils {

    /**
     * 获取给定异常最内层原因
     *
     * @param original 原始异常
     * @return 最内层异常
     */
    public static Throwable getRootCause(Throwable original) {
        if (null == original) {
            return null;
        }
        Throwable rootCause = null;
        Throwable cause = original.getCause();
        while (cause != null && cause != rootCause) {
            rootCause = cause;
            cause = cause.getCause();
        }
        return rootCause;
    }

}
